package Dao;

import Util.JBDCUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 管理员信息数据库访问类
 * @since 2024-06-09
 * @author yooo_fan
 */
public class ManagerDao {
    private static PreparedStatement preparedStatement = null;

    public static String getPassword() throws SQLException {
        String password = null;
        ResultSet data;
        try{
            data = ManagerDao.getPasswordData();
        }catch (SQLException e){
            throw new SQLException();
        }
        while(data.next()){
            password = data.getString("password");
        }
        return password;
    }

    private static ResultSet getPasswordData() throws SQLException {
        if(preparedStatement == null){
            String sql = "select password from manager_info limit 1";
            preparedStatement = JBDCUtil.getPreparedStatement(sql);
        }

        ResultSet result = preparedStatement.executeQuery();
        JBDCUtil.commit();
        return result;
    }
}
